package com.zues.daiommiddleware.socket;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.zues.daiommiddleware.controller.WebSocketServer;
import com.zues.daiommiddleware.result.HttpStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @ClassName AioClient
 * @Description TODO
 * @Author Administrator
 * @Date 2023/4/13 17:42
 * @Version 1.0
 **/
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/mes/aioClient")
public class AioClient {

    private final WebSocketServer webSocketServer;

    @RequestMapping(value = "/receiveMsg", method = RequestMethod.POST)
    public int receiveMsg(@RequestBody String json) {
        log.info("接收数据：" + json);
        JSONObject jsonObject = JSON.parseObject(json);
        JSONObject result = new JSONObject();
        String id = jsonObject.getString("userId");
        String msg = jsonObject.getString("msg");
        webSocketServer.sendOneMessage(id, msg);
        return HttpStatus.SUCCESS;
    }
}
